﻿using System.Web.Mvc;
using SilenthinkContract;
using System.Collections.Generic;
using SilenthinkContract.Domain;

namespace Web.VirtualProductHandler
{
    /// <summary>
    /// 处理虚拟拍币订单，用户支付成功后将等值的拍币发放给用户
    /// </summary>
    public class BidCurrencyHandler : IVirtualProductHandler
    {
        #region Implementation of IVirtualProductHandler

        private readonly IAuctionService auctionService;
        private readonly IPaymentService paymentService;
        public IList<int> SupportedId
        {
            get { return new[] { 1 }; }
        }

        public BidCurrencyHandler()
        {
            //auctionService = DependencyResolver.Current.GetService<IAuctionService>();
            //paymentService = DependencyResolver.Current.GetService<IPaymentService>();

            auctionService = Application.Container.GetInstance<IAuctionService>();
            paymentService = Application.Container.GetInstance<IPaymentService>();
        }

        public void Excute(AuctionOrder o)
        {
            if (Support(o))
            {
                string message;
                var status = paymentService.BidCurrencyIncrease(o.UserId, o.CreatedBy, (int)o.BuyPrice, true, 2, o.Id, string.Empty, out message);
                if (!status)
                {
                    Application.Logger.Warn("BidCurrencyHandler："+message);
                }
            }
        }

        private bool Support(AuctionOrder o)
        {
            return SupportedId.Contains(o.ProductId);
        }
        #endregion
    }
}